{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}

{% block title %}Sqoop
{% endblock %}

{% block content %}
<form action="" method="post" id="postattr" name="postattr">
    <input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
    <button type="submit" class="btn btn-primary">生成api</button>
    <th>{{ msg }}</th><br><br>

    <div class="form-row">
        <div class="form col-md-12">
            <label>Sqoop命令</label>
            <input type="text" id="sqoop_cmd" name="sqoop_cmd" class="form-control"></input>
        </div>
    </div>

    <div class="form-row">
        <div class="form col-md-2">
            <label>源数据库ip/域名</label>
            <input type="text" id="db_ip" name="db_ip" class="form-control" required="required"></input>
        </div>

        <div class="form col-md-1">
            <label>端口</label>
            <input type="number" id="db_port" name="db_port" class="form-control" required="required"></input>
        </div>

        <div class="from col-md-2">
            <label>库名</label>
            <input type="text" id="db_db" name="db_db" class="form-control" required="required"></input>
        </div>

        <div class="from col-md-2">
            <label>用户名</label>
            <input type="text" id="db_user" name="db_user" class="form-control" required="required"></input>
        </div>

        <div class="from col-md-2">
            <label>密码</label>
            <input type="text" id="db_passwd" name="db_passwd" class="form-control" required="required"></input>
        </div>

        <div class="from col-md-2">
            <label>属性分隔符</label>
            <input type="text" id="fields_terminated_by" name="fields_terminated_by" class="form-control" value="\t"></input>
        </div>

        <div class="from col-md-1">
            <label>行分隔符</label>
            <input type="text" id="lines_terminated_by" name="lines_terminated_by" class="form-control" value="\n"></input>
        </div>

    </div>

    <div class="form-row">
        <div class="from col-md-12">
            <label>表/查询SQL</label>
            <input type="text" id="db_sql" name="db_sql" class="form-control" required="required"></input>
        </div>
    </div>

    <div class="form-row">
        <div class="from col-md-2">
            <label>split_by</label>
            <input type="text" id="split_by" name="split_by" class="form-control" required="required"></input>
        </div>

        <div class="from col-md-1">
            <label>map数量</label>
            <input type="number" id="num_mappers" name="num_mappers" class="form-control" value="1"></input>
        </div>

        <div class="from col-md-2">
            <label>是否覆盖原数据</label>
            <select id="is_overwrite" name="is_overwrite" class="form-control" >
                <option value="1">覆盖</option>
                <option value="2">不覆盖</option>
            </select>
        </div>

        <div class="from col-md-4">
            <label>存储路径</label>
            <input type="text'" name="save_path" class="form-control"></input>
        </div>

        <div class="from col-md-2">
            <label>增量</label>
            <select name="increase_type" class="form-control" >
                <option value="1">不增量</option>
                <option value="2">年</option>
                <option value="3">月</option>
                <option value="4">日</option>
            </select>
        </div>
    </div>

    <div class="form-row">
        <div class="from col-md-2">
            <label>增量字段</label>
            <input type="text'" name="increase_column" class="form-control"></input>
        </div>

        <div class="from col-md-2">
            <label>增量字段类型</label>
            <select name="increase_data_type" class="form-control" >
                <option value="1">日期</option>
                <option value="2">字符串</option>
            </select>
        </div>

    </div>

    {% if (target_save == 1) %}
    <div class="form-row">
        <div class="from col-md-2">
            <label>hive db</label>
            <input type="text'" name="hive_db" class="form-control" required="required"></input>
        </div>

        <div class="from col-md-2">
            <label>hive table</label>
            <input type="text'" name="hive_table" class="form-control" required="required"></input>
        </div>

        <div class="from col-md-2">
            <label>是否分区</label>
            <select name="partition" class="form-control" >
                <option value="1">不分区</option>
                <option value="2">年</option>
                <option value="3">年,月</option>
                <option value="4">年,月,日</option>
            </select>
        </div>

        <div class="from col-md-2">
            <label>存储格式</label>
            <select name="save_format" class="form-control" >
                <option value="--as-textfile">text</option>
                <option value="--as-avrodatafile">avro</option>
                <option value="--as-sequencefile">sequence</option>
                <option value="--as-parquetfile">parquet</option>
            </select>
        </div>
    </div>

    {% elif (target_save == 2) %}
    <div class="form-row">
        <div class="from col-md-2">
            <label>存储格式</label>
            <select name="save_format" class="form-control" >
                <option value="--as-textfile">text</option>
                <option value="--as-avrodatafile">avro</option>
                <option value="--as-sequencefile">sequence</option>
                <option value="--as-parquetfile">parquet</option>
            </select>
        </div>

    </div>
    {% else %}
    <div class="form-row">
        <div class="from col-md-2">
            <label>hive db</label>
            <input type="text'" name="hive_db" class="form-control" required="required"></input>
        </div>

        <div class="from col-md-2">
            <label>hive table</label>
            <input type="text'" name="hive_table" class="form-control" required="required"></input>
        </div>

        <div class="from col-md-2">
            <label>是否分区</label>
            <select name="partition" class="form-control" >
                <option value="1">不分区</option>
                <option value="2">年</option>
                <option value="3">年,月</option>
                <option value="4">年,月,日</option>
            </select>
        </div>

    </div>
    {% endif %}

</form>

<br><br>
<table class="table table-bordered">
    <tr>
        <th>来源数据库</th>
        <th>来源表</th>
        <th>目标存储信息(表或路径)</th>
        <th>开发环境-调度api</th>
        <th>生产环境-调度api</th>
        <th>所有者</th>
    </tr>
        {% if json_data%}
            {% for i in json_data %}
                <tr>
                    <td>{{ i.get('source_db') }}</td>
                    <td>{{ i.get('source_table') }}</td>
                    <td>{{ i.get('target_info') }}</td>
                    <td>{{ url_for('api_sqoop_cmd', id=i.get('id'), env=0) }}</td>
                    <td>{{ url_for('api_sqoop_cmd', id=i.get('id'), env=1) }}</td>
                    <td>{{ i.get('owner') }}</td>

                </tr>
            {% endfor %}
        {% endif %}
    </table>
{% endblock %}


